package com.itheima.test4;

/**
 * @Author:gy
 * @Date: 2025/09/03 11:46
 * @Description:
 */
public class MyRunable implements Runnable {
    //定义一个计数器变量  共享
    private static int count = 0;
    //个人姓名
    private String name;
    //定义一个锁
    private static Object lock = new Object();
    //构造方法
    public MyRunable(String name) {
        this.name = name;
    }
    @Override
    public void run() {
        synchronized (lock) {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(name+"通过山洞,是第"+(++count)+"个通过的");
        }
    }
}
